<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>系统公告管理</title>
<link href="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/themes/default/css/ueditor.css" rel="stylesheet">
<script type="text/javascript" src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/ueditor.config.js"></script>
<script type="text/javascript" src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/ueditor.all.js"></script>
<script type="text/javascript" src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="${ctx}/jeasyui-extensions/jeasyui-extensions/jquery-easyui-ueditor/jquery.ueditor.js"></script>

<script type="text/javascript">
	var $grid;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			title : '系统公告管理',
			url : "${ctx}/basic/notice/dataGrid",
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'noticeTitle',
				title : '公告标题',
				sortable : true
			}, {
				field : 'noticeContent',
				title : '公告内容',
				width : 600,
				sortable : true
			}, {
				field : 'enable',
				title : '是否启用',
				formatter : function(value, row, index) {
					return '<input class="easyui-switchbutton" ' + (value == 1 ? "checked" : "")
					+ ' data-options="readonly:true,onText:\'是\',offText:\'否\'">';
				}
			} ] ]
		}));
		$grid.datagrid('enableFilter', [ {
			field : 'enable',
			type : 'combobox',
			javaType : 'I',
			options : {
				panelHeight : 'anto',
				data : [ {
					value : '',
					text : '全部'
				}, {
					value : '1',
					text : '是'
				}, {
					value : '2',
					text : '否'
				} ],
				onChange : function(value) {
					if (value == '') {
						$("#grid").datagrid('removeFilterRule', 'enable');
					} else {
						$("#grid").datagrid('addFilterRule', {
							field : 'enable',
							op : 'EQ',
							value : value
						});
					}
					$("#grid").datagrid('doFilter');
				}
			}
		} ]);
		
		$("#enableSB").switchbutton({
			onText : "是",
			offText : "否",
			checked : true,
			onChange : function(checked) {
				if (checked) {
					$("#enable").val(1);
				} else {
					$("#enable").val(2);
				}
			}
		});

		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load', {
				enable : 1
			});
			$("#enableSB").switchbutton('check');
			$("#dlg").dialog("open").dialog("setTitle", "新增系统公告");
		});
		
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法编辑",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$("#dlg").dialog("open").dialog("setTitle", "编辑系统公告");
				$("#fm").form("load", rowData);
				$("#enableSB").switchbutton(rowData.enable == 1 ? "check" : "uncheck");
			}
		});
		$("#deleteold").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法删除",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$.messager.confirm("您确定要进行该操作？", function(c) {
					if (c) {
						$.get("${ctx}/basic/notice/delete/" + rowData.id, function(result) {
							$.messager.show({
								msg : result.msg,
								icon : "info",
								position : "bottomRight"
							});
							if (result.success) {
								$grid.datagrid("load");
							}
						}, 'json');
					}
				});
			}
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/basic/notice/multiDelete");
		});
		$("#search").click(function() {
			$grid.datagrid('load', $("#tt").form("getData"));
		});
		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "SystemConfig",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
		$("#excelExport").click(function() {
			window.parent.location.href = "${ctx}/basic/notice/excelExport?" + $.param($grid.datagrid('options').queryParams);
		});
	});
	function fn_save() {
		$("#fm").form("submit", {
			url : "${ctx}/basic/notice/update",
			success : function(data) {
				$grid.datagrid("load");
				$.messager.show({
					msg : data.msg,
					icon : "info",
					position : "bottomRight"
				});
				$("#dlg").dialog('close');
			}
		});
	}
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="easyui-toolbar">
		<!-- 	<span>系统公告名称：</span>
	      <input type="text" name="search_LIKE_noticeName" style="margin-left: 2px; margin-right: 2px; padding-left: 2px; padding-right: 3px;" />
		<a id="search" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-hamburg-zoom'">查询</a> -->
		<div class="row"></div>
		<div class="col-md-12">
			<shiro:hasPermission name="notice:update">
				<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="notice:delete">
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="notice:import">
				<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导入
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="notice:export">
				<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导出
				</button>
			</shiro:hasPermission>
			</div>
	</div>
	<shiro:hasPermission name="notice:update">
		<div id="dlg" class="easyui-dialog" style="width: 720px; height: 480px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" />
				<table id="tbl">
					<tr>
						<td><label>系统公告标题:</label></td>
						<td><input name="noticeTitle" class="easyui-validatebox" data-options="required: true,height: 30,width:508,"></td>
					</tr>
					<tr>
						<td><label>是否启用:</label></td>
						<td><input id="enable" name="enable" type="hidden"> <input id="enableSB"></td>
					</tr>
					<tr>
						<td><label>系统公告内容:</label></td>
						<td><textarea name="noticeContent" class="easyui-ueditor"
								data-options="
                              required: true, height: 260,width:508, value: '',
                              template: 'simple',
                              codeMirrorJsUrl: false, codeMirrorCssUrl: false
                              "></textarea></td>
					</tr>
				</table>
			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="fn_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>
	</shiro:hasPermission>
</body>
</html>
